<%--
  Created by IntelliJ IDEA.
  User: best魔王
  Date: 2019/8/1
  Time: 15:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>测试</title>

    <meta charset="utf-8">
    <!-- 引入 ECharts 文件 -->
    <script src="/js/echarts.min.js"></script>
    <script src="/js/jquery-3.2.1min.js"></script>
</head>
<body>




<%--js更新任务状态--%>
<script>
    function updateState(reportId,state) {
    $.ajax({
    url:"/UpdateState?reportId="+reportId+"&state="+state,
    contentType:"application/json;charset=UTF-8",
    data:{},
    type:"post",
    success:function (data) {
    location.reload();

    },
    error:function () {
    alert("审核出现错误");
    }
    })
    };
</script>








图标测试
<!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
<div id="main" style="width: 600px;height:400px;"></div>


<%--摄像头测试--%>
<div id="contentHolder">
    <video id="video" width="320" height="320" autoplay></video>
    <button id="start" style="display:block" >start</button>
    <button id="picture" style="display:block" >paizhao</button>
    <canvas style="display:block" id="canvas" width="320" height="320"></canvas>
    <button id="sc" style="display:block" >shangchuan</button>
    <button id="stop" style="display:block" >stop</button>
</div>





<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    // 指定图表的配置项和数据
    var option = {
        title: {
            text: 'ECharts 入门示例'
        },
        tooltip: {},
        legend: {
            data:['销量']
        },
        xAxis: {
            data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
</script>





<%--调用本地摄像头脚本--%>

<script>
    var mediaStreamTrack;
    document.getElementById("start").addEventListener("click", function () {
        navigator.getUserMedia = navigator.getUserMedia ||
            navigator.webkitGetUserMedia ||
            navigator.mozGetUserMedia;
        if (navigator.getUserMedia) {
            navigator.getUserMedia({ audio: true, video: { width: 320, height: 320 } },
                function(stream) {
                    mediaStreamTrack = typeof stream.stop === 'function' ? stream : stream.getTracks()[1];
                    video.src = (window.URL || window.webkitURL).createObjectURL(stream);
                    video.play();
                    /*  var video = document.getElementById("video");
                     video.src = window.URL.createObjectURL(stream);
                     video.onloadedmetadata = function(e) {
                         console.log('nihao44eee4aaaaddda');
                         video.play();
                     }; */
                },
                function(err) {
                    console.log("The following error occurred: " + err.name);
                }
            );
        } else {
            console.log("getUserMedia not supported");
        }
    });
    document.getElementById("stop").addEventListener("click", function () {
        mediaStreamTrack && mediaStreamTrack.stop();
    });
    document.getElementById("picture").addEventListener("click", function () {
        var context = document.getElementById("canvas").getContext("2d");
        context.drawImage(video, 0, 0, 320, 320);
    });
    document.getElementById("sc").addEventListener("click", function () {
        var imgData=document.getElementById("canvas").toDataURL("image/png");
        var mmmd=getBase64Image(document.getElementById("mmm"));
        var data=imgData.substr(22);
        console.log(mmmd)
        debugger
        $.post('recorder/target/sc',{'sj':data});
    });
    function getBase64Image(img) {
        var canvastemp = document.createElement("canvas");
        canvastemp.width = img.width;
        canvastemp.height = img.height;
        var ctx = canvas.getContext("2d");
        ctx.drawImage(img, 0, 0, img.width, img.height);
        var dataURL = canvas.toDataURL("image/png");
        return dataURL
        // return dataURL.replace("data:image/png;base64,", "");
    }
</script>



</body>
</html>
